package com.rf.richfitwheel;

import com.ulisesbocchio.jasyptspringboot.annotation.EnableEncryptableProperties;
import io.micrometer.core.instrument.MeterRegistry;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.actuate.autoconfigure.metrics.MeterRegistryCustomizer;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.amqp.RabbitAutoConfiguration;
import org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration;
import org.springframework.boot.autoconfigure.data.redis.RedisRepositoriesAutoConfiguration;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.netflix.hystrix.security.HystrixSecurityAutoConfiguration;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.scheduling.annotation.EnableScheduling;

import javax.annotation.PostConstruct;

/**
 * 因为要配置对个redis链接，所以将系统自带的配置排除，分别是
 * RedisAutoConfiguration.class 和 RedisRepositoriesAutoConfiguration.class
 * 两个自动配置类
 * 需要注意的是：RedisRepositoriesAutoConfiguration 对 beanName 叫做 “redisTemplate” 的bean有依赖，需要一并排除
 *
 * @author hushouquan
 *
 */
@SpringBootApplication(exclude={
        org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration.class,
        HystrixSecurityAutoConfiguration.class,
        RedisAutoConfiguration.class,
        RedisRepositoriesAutoConfiguration.class,
        RabbitAutoConfiguration.class
})
@EnableDiscoveryClient
@EnableFeignClients
@MapperScan(basePackages={"com.rf.richfitwheel.**.dao"})
@EnableScheduling
@EnableCaching
@EnableEncryptableProperties
@EnableAspectJAutoProxy
@EnableConfigurationProperties
public class AdminServiceApplication  {
    public static void main(String[] args) {
        SpringApplication.run(AdminServiceApplication.class, args);
    }

    @Bean
    MeterRegistryCustomizer<MeterRegistry> configurer(@Value("${spring.application.name}") String applicationName) {
        return (registry) -> registry.config().commonTags("application", applicationName);
    }

}